;/*****************************************************************************
; * @file:    startup_CM0.s
; * @purpose: CMSIS Cortex-M0 Core Device Startup File 
; *           for the ARM 'Microcontroller Prototyping System' 
; * @version: V1.0
; * @date:    
; *
; *****************************************************************************/
Stack_Size      EQU     0x00002000
Heap_Size       EQU     0x00000000
;__initial_sp    EQU    0x20003000       ;Define SP size

                AREA    STACK, NOINIT, READWRITE, ALIGN=3
Stack_Mem       SPACE   Stack_Size
__initial_sp

                AREA    HEAP, NOINIT, READWRITE, ALIGN=3
__heap_base
Heap_Mem        SPACE   Heap_Size
__heap_limit

                PRESERVE8
                THUMB

; Vector Table Mapped to Address 0 at Reset

                AREA    RESET, DATA, READONLY
                EXPORT __Vectors

__Vectors       
				DCD     __initial_sp                ; Top of Stack
                DCD     Reset_Handler               ; Reset Handler
                DCD     NMI_Handler                 ; NMI Handler
                DCD     HardFault_Handler           ; Hard Fault Handler
                DCD     MemManage_Handler           ; MPU Fault Handler
                DCD     BusFault_Handler            ; Bus Fault Handler
                DCD     UsageFault_Handler          ; Usage Fault Handler
                DCD     0                           ; Reserved
                DCD     0                           ; Reserved
                DCD     0                           ; Reserved
                DCD     0                           ; Reserved
                DCD     SVC_Handler                 ; SVCall Handler,SWI
                DCD     DebugMon_Handler            ; Debug Monitor Handler
                DCD     0                           ; Reserved
                DCD     PendSV_Handler              ; PendSV Handler
                DCD     SysTick_Handler             ; SysTick Handler

                ; External Interrupts
                DCD     RSV0_IRQHandler				; 0 
				DCD     LVD_IRQHandler				; 1:  EXTI16				
                DCD     RSV2_IRQHandler			    ; 2
				DCD     RSV3_IRQHandler		        ; 3					
				DCD     RSV4_IRQHandler	            ; 4
				DCD     RSV5_IRQHandler             ; 5
				DCD     CLKRDY_IRQHandler		        ; 6
				DCD     EXTI0_IRQHandler		    ; 7
				DCD     EXTI1_IRQHandler		    ; 8
				DCD     EXTI2_IRQHandler		    ; 9
				DCD     EXTI3_IRQHandler		    ; 10
				DCD     EXTI4_IRQHandler		    ; 11
				DCD     PCOM_IRQHandler		        ; 12                   
				DCD     EXTI9_5_IRQHandler		    ; 13
				DCD     TIM3_IRQHandler		        ; 14
				DCD     TIM6_IRQHandler		        ; 15
				DCD     TIM15_IRQHandler		    ; 16
				DCD     I2C1_IRQHandler		        ; 17
				DCD     SPI1_IRQHandler		        ; 18                      
				DCD     SPI2_IRQHandler             ; 19	
				DCD     RSV20_IRQHandler            ; 20 	
				DCD     UART1_IRQHandler            ; 21
				DCD     UART2_IRQHandler            ; 22
				DCD     EXTI15_10_IRQHandler        ; 23
				DCD     AES_IRQHandler	            ; 24
				DCD     FPU_IRQHandler              ; 25
				DCD     IWDT_WKUP_IRQHandler        ; 26
				DCD    	TIM14_IRQHandler            ; 27
				DCD    	SPI7_IRQHandler		        ; 28
                
                AREA    |.text|, CODE, READONLY

Reset_Handler   PROC
                EXPORT  Reset_Handler             [WEAK]
                IMPORT  __main
                IMPORT  main
                IMPORT  SystemInit

                    

                LDR     R0, =SystemInit
                BLX     R0
 
                
                LDR     R0, =__main
                BX      R0                  ;
                ENDP


NMI_Handler     PROC
                EXPORT  NMI_Handler                [WEAK]
                B       .
                ENDP
HardFault_Handler\
                PROC
                EXPORT  HardFault_Handler          [WEAK]
                B       .
                ENDP
MemManage_Handler\
                PROC
                EXPORT  MemManage_Handler          [WEAK]
                B       .
                ENDP
BusFault_Handler\
                PROC
                EXPORT  BusFault_Handler           [WEAK]
                B       .
                ENDP
UsageFault_Handler\
                PROC
                EXPORT  UsageFault_Handler         [WEAK]
                B       .
                ENDP
SVC_Handler     PROC
                EXPORT  SVC_Handler                [WEAK]
                B       .
                ENDP
DebugMon_Handler\
                PROC
                EXPORT  DebugMon_Handler           [WEAK]
                B       .
                ENDP
PendSV_Handler  PROC
                EXPORT  PendSV_Handler             [WEAK]
                B       .
                ENDP
SysTick_Handler PROC
                EXPORT  SysTick_Handler            [WEAK]
                B       .
                ENDP

Default_Handler PROC
                EXPORT     RSV0_IRQHandler          [WEAK]
                EXPORT     LVD_IRQHandler           [WEAK]                
                EXPORT     RSV2_IRQHandler          [WEAK]
                EXPORT     RSV3_IRQHandler          [WEAK]        
                EXPORT     RSV4_IRQHandler          [WEAK]
                EXPORT     RSV5_IRQHandler          [WEAK]
                EXPORT     CLKRDY_IRQHandler        [WEAK]
                EXPORT     EXTI0_IRQHandler         [WEAK]
                EXPORT     EXTI1_IRQHandler         [WEAK]
                EXPORT     EXTI2_IRQHandler         [WEAK]
                EXPORT     EXTI3_IRQHandler         [WEAK]
                EXPORT     EXTI4_IRQHandler         [WEAK]
                EXPORT     PCOM_IRQHandler          [WEAK]           
                EXPORT     EXTI9_5_IRQHandler       [WEAK]
                EXPORT     TIM3_IRQHandler          [WEAK]
                EXPORT     TIM6_IRQHandler          [WEAK]
                EXPORT     TIM15_IRQHandler         [WEAK]
                EXPORT     I2C1_IRQHandler          [WEAK]
                EXPORT     SPI1_IRQHandler          [WEAK]
                EXPORT     SPI2_IRQHandler          [WEAK]
                EXPORT     RSV20_IRQHandler         [WEAK]
                EXPORT     UART1_IRQHandler         [WEAK]
                EXPORT     UART2_IRQHandler         [WEAK]
                EXPORT     EXTI15_10_IRQHandler     [WEAK]
                EXPORT     AES_IRQHandler           [WEAK]
                EXPORT     FPU_IRQHandler           [WEAK] 
                EXPORT     IWDT_WKUP_IRQHandler     [WEAK]
                EXPORT     TIM14_IRQHandler         [WEAK]
                EXPORT     SPI7_IRQHandler          [WEAK]
				

										
RSV0_IRQHandler
LVD_IRQHandler
RSV2_IRQHandler
RSV3_IRQHandler
RSV4_IRQHandler
RSV5_IRQHandler
CLKRDY_IRQHandler
EXTI0_IRQHandler
EXTI1_IRQHandler
EXTI2_IRQHandler
EXTI3_IRQHandler
EXTI4_IRQHandler
PCOM_IRQHandler
EXTI9_5_IRQHandler
TIM3_IRQHandler
TIM6_IRQHandler
TIM15_IRQHandler
I2C1_IRQHandler
SPI1_IRQHandler
SPI2_IRQHandler
RSV20_IRQHandler
UART1_IRQHandler
UART2_IRQHandler
EXTI15_10_IRQHandler        
AES_IRQHandler
FPU_IRQHandler
IWDT_WKUP_IRQHandler
TIM14_IRQHandler
SPI7_IRQHandler

                B        .
                ENDP                                                                  
                 
                ALIGN
                                 
; User Initial Stack & Heap
                 
                IF      :DEF:__MICROLIB
                 
                EXPORT  __initial_sp
                EXPORT  __heap_base
                EXPORT  __heap_limit
                 
                ELSE
                 
                IMPORT  __use_two_region_memory
                EXPORT  __user_initial_stackheap
__user_initial_stackheap
                 
                LDR     R0, =  Heap_Mem
                LDR     R1, =(Stack_Mem + Stack_Size)
                LDR     R2, = (Heap_Mem +  Heap_Size)
                LDR     R3, = Stack_Mem
                BX      LR

                ALIGN

                ENDIF

                END
